package page;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.junit.Test;

import util.DBPoolUtils;

public class PageDemo {

	@Test
	public void page() throws SQLException {
		int page = 2;
		int pageSize = 3;
		
		Connection c = DBPoolUtils.getConnection();
		String sql = "select empno,ename from emp limit ?,?";
		
		PreparedStatement ps = c.prepareStatement(sql);
		ps.setInt(1, (page-1) * pageSize);
		ps.setInt(2, pageSize);
		
		ResultSet set = ps.executeQuery();
		while(set.next()) {
			System.out.println(set.getInt(1) +"," + set.getString(2));
		} 
		
		ps.close();
		c.close();
	}
}
